package com.book.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {//鏃ユ湡杞崲宸ュ叿绫�
	
	static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
	
	/**
	 * 鎶奃ate杞垚瀛楃涓�
	 * @param date 瑕佽浆鎹㈢殑鏃ユ湡
	 * @return 杩斿洖杞崲鍚庣殑鏃ユ湡瀛楃涓�
	 * */
	public static String dateToString(Date date){
		return sdf.format(date);
	}
	
	/**
	 * 鎶婂瓧绗︿覆杞垚Date
	 * @param date 瑕佽浆鎹㈡垚鏃ユ湡鐨勫瓧绗︿覆
	 * @return 杩斿洖杞崲鍚庣殑鏃ユ湡
	 * */
	public static Date stringToDate(String date){
		try {
			return sdf.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
}
